<div class="box-page-container">
  <div class="box-page-header">
    <div class="title">Новости</div>
    <div class="other-controls right">
    </div>
  </div>
  <div class="box-page-body">
	<?php if (count($this->news) <= 0): ?>
		Ни одной новости еще не создано.
	<?php else: ?>
    	<table class="table">
	      <thead>
	        <tr>
			  <th width="220px">Заголовок</th>
			  <th width="80px">Автор</th>
			  <th width="80px">Комментарий</th>
			  <th width="90px">Опубликовано</th>
			  <th width="40px"></th>
			</tr>
	      </thead>
	      <tbody>
		  <?php foreach($this->news as $news): ?>
			<tr id="<?php echo $news->id ?>">
				<td><?php echo $news->title ?></td>
				<td><?php echo $news->findParentRow('Model_User')->name ?></td>
				<td><?php echo count($news->findDependentRowset('Model_NewsComments')) ?></td>
				<td><?php 
					$date = new Zend_Date($news->created, false, Pidguin_Application::getInstance()->getLocale());
					echo $date->toString('dd MMMM YYYYг.');
				?></td>
				<td>
					<div class="control-bar">
						<a href="/cp/news/edit?id=<?php echo $news->id ?>" title="Редактировать"><i class="icon-pencil"></i></a>
						<a href="#" title="Удалить" onclick="dDelete(this); return false;"><i class="icon-trash"></i></a>
					</div>
				</td>
			</tr>
		  <?php endforeach; ?>
	      </tbody>
	    </table>
	<?php endif; ?>
  </div>
  <div class="box-page-footer">
    <div class="box-controls">
      <div class="right">
       	<div class="btn"><button onclick="window.location = '/cp/news/create'; return false;" class="primary">Создать новость</button></div>
      </div>
      <div id="progress" class="progress ajax-preloader-base"></div>
      <div id="control_text" class="box-controls-text"></div>
      <div class="clear-fix"></div>
    </div>
  </div>
  <div class="clear-fix"></div>
</div>
<script>
function dDelete(el) {
	var title = $(el).parent().parent().parent().find('td').eq(0).text();
	var id = $(el).parent().parent().parent().attr('id');
	var ddel = new goog.ui.Dialog(null, true);
	// new page content
	var ddelc = '<div>Вы действительно хотите удалить новость <b>' + title + '</b>?</div>';
	ddel.setContent(ddelc);
	ddel.setTitle('Подтвердите удаление');
	ddel.setButtonSet(
		new goog.ui.Dialog.ButtonSet()
		.addButton({key: 'ok', caption: 'Да'}, true)
		.addButton({key: 'cancel', caption: 'Нет'}, false, true)
	);
	ddel.setVisible(true);
	$(ddel.getElement()).css({'width': '450px', 'left': (document.width / 2) - 225 + 'px'});
	goog.events.listen(ddel, goog.ui.Dialog.EventType.SELECT, function(e){
		if (e.key == 'ok') {
			window.location = '/cp/news/delete?id=' + id;
		}
	});
}
</script>